@extends('layouts.home')
@extends('layouts.nav')
@extends('layouts.top')

@section('css')
    <style>
        select{margin:10px 0}
    </style>
    <link rel="stylesheet" type="text/css" href="{{ asset('files/js/jquery-multi-select/css/multi-select.css') }}"/>
    <link rel="stylesheet" type="text/css"
          href="{{ asset('files/js/bootstrap-datepicker/css/datepicker-custom.css')}}"/>
@endsection

@section('heading')
    <h3>
        统计管理
    </h3>
    <ul class="breadcrumb">
        <li>
            <a href="#">统计管理</a>
        </li>
        <li class="active"> 订单管理</li>
    </ul>
@endsection

@section('wrapper')
    @include('share.error')

    <div class="row">
        <div class="col-sm-12">
            <section class="panel">
                <header class="panel-heading" style="overflow: hidden;">
                    &nbsp;
                    <span class="tools pull-right">
                        <form action="{{ route('orders.index') }}" class="form-horizontal ">
                                <div class="form-group row" style="overflow: hidden; margin-left: 15px;">
                                    <input type="text" class="form-control" name="number" placeholder="请输入订单号"
                                           style="float:left;margin-right: 10px;width: 200px"
                                           value="{{ request()->get('number') }}"/>
                                    <input type="text" class="form-control" name="title" placeholder="请输入课程名"
                                           style="float:left;margin-right: 10px;width: 200px"
                                           value="{{ request()->get('title') }}"/>
                                    <input type="text" class="form-control" name="tel" placeholder="请输入手机号"
                                           style="float:left;margin-right: 10px;width: 200px"
                                           value="{{ request()->get('tel') }}"/>
                                    <label class="control-label " style="float: left;margin-right:5px;">金额筛选</label>
                                    <input type="text" class="form-control" name="from_p" placeholder="0"
                                           style="float:left;margin-right: 10px;width: 55px"
                                           value="{{ request()->get('from_p') }}"/>
                                    <input type="text" class="form-control" name="to_p" placeholder="100"
                                           style="float:left;margin-right: 10px;width: 55px"
                                           value="{{ request()->get('to_p') }}"/>
                                    <div style="overflow: hidden;float: left;">
                                        <label class="control-label " style="float: left;margin:10px 0;">时间筛选</label>
                                        <div style="float: left;width: 300px;margin: 10px;">
                                            <div class="input-group input-large custom-date-range" data-date="2013/07/13"
                                                 data-date-format="yyyy/mm/dd HH:ii:ss">
                                                <input type="text" value="{{ request()->get('from') }}"
                                                       class="form-control dpd1" readonly name="from">
                                                <span class="input-group-addon">To</span>
                                                <input type="text" value="{{ request()->get('to') }}"
                                                       class="form-control dpd2" readonly name="to">
                                            </div>
                                        </div>
                                        <select class="form-control" id="province" name="province_id"
                                                style="float:left;width:200px;margin-right: 30px;">
                                            <option value="">请选择省</option>
                                            @foreach($provinces as $province)
                                                <option {{ request()->get('province_id') == $province->id ? 'selected' : '' }} value="{{ $province->id }}"> {{ $province->name }}</option>
                                            @endforeach
                                        </select>
                                        <select class="form-control" id="city" name="city_id"
                                                style="float:left;width:200px;margin-right: 30px;">
                                            <option value="">请选择市</option>
                                            @foreach($citys as $city)
                                                <option {{ request()->get('city_id') == $city->id ? 'selected' : '' }} value="{{ $city->id }}"> {{ $city->name }}</option>
                                            @endforeach
                                        </select>
                                        <select id="area" class="form-control" name="area_id"
                                                style="float:left;width:200px;margin-right: 30px;">
                                            <option value="">请选择区/县</option>
                                            @foreach($areas as $area)
                                                <option {{ request()->get('area_id') == $area->id ? 'selected' : '' }} value="{{ $area->id }}"> {{ $area->name }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div style="float: right;margin-top: 10px;">
                                    <button class="btn btn-success" type="submit"
                                            style="float: right;margin-right:10px;">查询</button>
                                    <button class="btn btn-success"
                                            onclick='location.href="{{ route('orders.export') }}?title={{ request()->get('title') }}&tel={{ request()->get('tel') }}&number={{ request()->get('number') }}&from_p={{ request()->get('from_p') }}&to_p={{ request()->get('to_p') }}&from={{ request()->get('from') }}&to={{ request()->get('to') }}&province_id={{ request()->get('province_id') }}&city_id={{ request()->get('city_id') }}&area_id={{ request()->get('area_id') }}"'
                                            type="button" style="float: right;margin-right:10px;">导出</button></div>
                                </div>
                            </form>
                    </span>
                </header>
                <div class="panel-body">
                    <table class="table  table-hover general-table">
                        <thead>
                        <tr>
                            <th>订单号</th>
                            <th>课程名称</th>
                            <th>教师</th>
                            <th>价格</th>
                            <th>昵称</th>
                            <th>手机号</th>
                            <th>省</th>
                            <th>市</th>
                            <th>区</th>
                            <th>状态</th>
                            <th>订单时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($orders as $order)
                            <tr>
                                <td>{{ $order->number }}</td>
                                <td>{{ $order->item->video->title }}</td>
                                <td>{{ $order->item->video->teacher->name }}</td>
                                <td>{{ number_format($order->total,2) }}</td>
                                <td>{{ $order->author->info->name }}</td>
                                <td>{{ $order->author->tel }}</td>
                                <td>{{ $order->author->info->province }}</td>
                                <td>{{ $order->author->info->city }}</td>
                                <td>{{ $order->author->info->privilege }}</td>
                                <td>{{ $order->state}}</td>
                                <td>{{ $order->created_at }}</td>
                            </tr>
                        @endforeach


                        </tbody>
                    </table>
                    <div>
                        <ul class="pagination pagination-lg">
                            {{ $orders->links() }}
                        </ul>
                    </div>
                </div>

            </section>
        </div>
    </div>
@endsection

@section('js')
    <script type="text/javascript">
        $("#province").change(function () {
            var province = $(this).find("option:selected").val();
            if (province) {
                $.ajax({
                    type: "get",
                    url: "{{ route('orders.cities') }}",
                    data: "province=" + province,
                    success: function (msg) {
                        if (msg) {
                            var s = "<option value=''>请选择市</option>";
                            var data = JSON.parse(msg);
                            for (var i = 0; i < data.length; i++) {
                                s += "<option value='" + data[i]['id'] + "'>" + data[i]['name'] + "</option>";
                                $("#city").html(s);
                            }
                        }
                    }
                });
            }
        });

        $("#city").change(function () {
            var city_id = $(this).find("option:selected").val();
            if (city_id) {
                $.ajax({
                    type: "get",
                    url: "{{ route('orders.areas') }}",
                    data: "city_id=" + city_id,
                    success: function (msg) {
                        if (msg) {
                            var s = "<option value=''>请选择区/县</option>";
                            var data = JSON.parse(msg);
                            for (var i = 0; i < data.length; i++) {
                                s += "<option value='" + data[i]['id'] + "'>" + data[i]['name'] + "</option>";
                                $("#area").html(s);
                            }
                        }
                    }
                });
            }
        });
    </script>
    <script type="text/javascript"
            src="{{ asset('files/js/bootstrap-datepicker/js/bootstrap-datepicker.js') }}"></script>
    <script src="{{ asset('files/js/pickers-init.js') }}"></script>
@endsection